<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
}
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'订单总列表'),
	
);
$return['status']=$this->order_status;
if($_RQ['op']=='list'){
	$params=array('animal_id >'=>0);
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	
	}if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','total','uniacid','sendtype','land_id','seed_id','mid','animal_id','ordersn','money','pay','username','mobile','address','status','createtime');
	$list=pdo_getslice('jy_farmer_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$animal=pdo_get('jy_farmer_animal',array('id'=>$item['animal_id'],'uniacid'=>$_SESSION['uniacid']));
			$item['aclassify_title']=pdo_getcolumn('jy_farmer_aclassify',array('id'=>$animal['classify_id'],'uniacid'=>$_SESSION['uniacid']),'title');
			$item['animal_title']=$animal['title'];
			$item['createtime']=date('Y-m-d h:i',$item['createtime']);
			$item['expressid']=pdo_getcolumn('jy_farmer_order_express',array('orderid'=>$item['id']),'id');
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单编号','type'=>'string'),
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('type'=>'img_string','title'=>'联系人/电话',
			'data'=>array(
				array('title'=>'','name'=>'username'),
				array('title'=>'','name'=>'mobile')
				)
			),
			array('name'=>'aclassify_title','title'=>'家禽分类','type'=>'string'),
			array('name'=>'animal_title','title'=>'家禽名称','type'=>'string'),
			array('name'=>'total','title'=>'数量','type'=>'string'),
			array('name'=>'createtime','title'=>'下单时间','type'=>'string'),
			array('name'=>'money','title'=>'金额','type'=>'string'),
			array('name'=>'sendtype','title'=>'领取方式','type'=>'radio','options'=>'sendtype'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),'action'=>array(
			array('action'=>'/express/','title'=>'查看物流_Express','type'=>'modal','show'=>array('status'=>3,'expressid >'=>0)),
			array('action'=>'/a_order/fa/','title'=>'发货_Ship','type'=>'href','show'=>array('status'=>6)),
		)),
		'search'=>array(
			array('name'=>'name','width'=>15,'title'=>'用户昵称','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'订单状态','type'=>'select','options'=>'status_select'),
		)
	);
	$return['status_select']=array('0'=>array('id'=>'0','title'=>'待支付'),'1'=>array('id'=>'1','title'=>'已支付'),'2'=>array('id'=>'2','title'=>'已取消'));
	$return['htmls']=$htmls;
	$return['sendtype']=$this->send_types;
	exi($return);
}
if($_RQ['op']=='fa'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$id){
			exi('参数错误！','error');
		}
		if(!$post['express'] || !$post['expresssn']){
			exi('请填写快递信息','error');
		}
		$data=array('express'=>$post['express'],'expresssn'=>$post['expresssn']);
		$this->model('order')->order_send($id,$data);
		exi('已发货！','','list');
	}
	$id=intval($_RQ['id']);
	$item=$this->pdo_get('order',array('id'=>$id));	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'订单发货',
	);
	$tip='商品订单已打包好,快递发货！';		
	$htmls['edit']=array(
			array('type'=>'tip','title'=>$tip),
			array('type'=>'copy','name'=>'address','title'=>'收货地址'),
			array('type'=>'select','title'=>'快递公司','name'=>'express','options'=>'express','option_title'=>'name'),
			array('type'=>'string','title'=>'快递单号','name'=>'expresssn'),
	);
	$return['express']=model('jy_weishop/model')->express_types();
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
